package web.Users;

import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        //获取传过来的ID
        String user_id = request.getParameter("user_id");

        User_Service user_service = new User_ServiceImpl();
        /*调用service查询*/
        if (user_service.delUser(user_id))
        {
            /*重定向*/
            response.sendRedirect("allUserServlet");
        }
        else
        {
            request.setAttribute("delError","删除失败");
            request.getRequestDispatcher("allUserServlet").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
